
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 求斐波那契数列第n项的值
        function fibonacci(n) {
            //判断值是否合法
            if (n < 0) {
                return "输入的值不能为0或负数";
            }
            if (n <= 1) {
                return n;
            } else {
                return fibonacci(n - 1) + fibonacci(n - 2);
            }
        }
        // 测试
        console.log(fibonacci(10)); // 输出55
    </script>
</body>
</html>